/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-03-14
 * Time:21:27
 */
class Solution {
    //左闭右开
    public int search(int[] nums, int target) {
        if(nums.length<=0){
            return -1;
        }
        int left=0;
        int right= nums.length;
        while(left<right){
            int mid=left+(right-left)/2;
            if(nums[mid]>target){
                right=mid;
            }else if(nums[mid]<target){
                left=mid+1;
            }else {
                return mid;
            }
        }
        return -1;
    }
    //左闭右闭
    public int search2(int[] nums, int target) {
        int left=0;
        int right= nums.length-1;
        while(left<=right){
            int mid=left+(right-left)/2;
            if(nums[mid]>target){
                right=mid-1;
            }else if(nums[mid]<target){
                left=mid+1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
public class Test {
}
